package com.lxyk.yygh.hosp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lxyk.yygh.common.exception.YyghException;
import com.lxyk.yygh.common.result.ResultCodeEnum;
import com.lxyk.yygh.hosp.mapper.HospitalSetMapper;
import com.lxyk.yygh.hosp.service.HospitalSetService;
import com.lxyk.yygh.model.hosp.HospitalSet;
import com.lxyk.yygh.vo.order.SignInfoVo;
import org.springframework.stereotype.Service;

@Service
public class HospitalSetServiceImpl extends ServiceImpl<HospitalSetMapper, HospitalSet> implements  HospitalSetService {

    /**
     * //    根据hoscode获取签名,上传医院进行签名比对
     * @param hoscode
     * @return
     */
    @Override
    public String getSignKey(String hoscode) {
        QueryWrapper<HospitalSet> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("hoscode",hoscode);
        HospitalSet hospitalSet = baseMapper.selectOne(queryWrapper);
        return hospitalSet.getSignKey();
    }

    //获取医院签名信息,远程调用
    @Override
    public SignInfoVo getSignInfoVo(String hoscode) {
        LambdaQueryWrapper<HospitalSet> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(HospitalSet::getHoscode,hoscode);
        HospitalSet hospitalSet = baseMapper.selectOne(queryWrapper);
        if(hospitalSet==null){

            throw new YyghException(ResultCodeEnum.DATA_ERROR);
        }

        SignInfoVo signInfoVo = new SignInfoVo();
        signInfoVo.setSignKey(hospitalSet.getSignKey());
        signInfoVo.setApiUrl(hospitalSet.getApiUrl());
        return signInfoVo;
    }
}
